package com.egame.manage.biz.server.gc;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import com.egame.manage.biz.server.ManageClient;
import cn.egame.common.exception.ExceptionCommonBase;
import cn.egame.interfaces.fl.FileInfo;
import cn.egame.interfaces.gc.GameFileInfo;

public class GameFileServiceImpl {

	private static GameFileServiceImpl instance = null;
	private static byte[] SyncRoot = new byte[1];
	private GameFileServiceDao dao = null;
	
	public static GameFileServiceImpl getInstance() throws ExceptionCommonBase {
		if (instance == null) {
			synchronized (SyncRoot) {
				if (instance == null) {
					instance = new GameFileServiceImpl();
				}
			}
		}
		return instance;
	}
	
	public GameFileServiceImpl() throws ExceptionCommonBase{
		super();
		dao = new GameFileServiceDao();
	}
	
	public int changeFileStatus(long fileId,int status) throws ExceptionCommonBase{
		return dao.updateFileStatus(fileId, status);
	}
		
	public int setFileRemark(long fileId,String remark) throws ExceptionCommonBase{
		return dao.setFileRemark(fileId, remark);
	}

	public List<GameFileInfo> listGameFileInfoByGid(int appId,long loginUserId,int gid)throws RemoteException{
		List<Integer> fids = dao.listGameFileIdsByGid(gid);
		if(fids != null && fids.size()>0){
			return ManageClient.getInstance().listGameFileInfoByIds(appId, loginUserId, fids);
		}
		return new ArrayList<GameFileInfo>();
	}
	
	public int deleteGameFileById(int appId,long loginUserId,long fid)throws ExceptionCommonBase{
		return dao.deleteGameFileById(fid);		
	}

	public long setGameFile(int appId,long loginUserId,long efsid,int gid,FileInfo file)throws Exception{
		return dao.setGameFile(appId, loginUserId, efsid,gid, file);
	}

	public int getFileCountByGId(int gId) throws ExceptionCommonBase{
		return dao.getFileCountByGId(gId);
	}
	
	public int getFileLinkCountByGid(int gId) throws ExceptionCommonBase{
		return dao.getFileLinkCountByGid(gId);
	}
//	
//	public long getAdaptFile(int gid)throws ExceptionCommonBase{
//		return dao.getAdaptFile(gid);
//	}

	public boolean hasAdapted(int gid,int terminalId)throws ExceptionCommonBase{
		return dao.hasAdapted(gid,terminalId);
	}
	
	public GameFileInfo getGameFileInfo(int appId,long loginUserId,long fid)throws RemoteException{
		GameFileInfo bean = ManageClient.getInstance().getGameFileInfoById(appId, loginUserId, fid);
		if(bean == null) bean = new GameFileInfo();
		return bean;
	}

	public List<String[]> listPackageName(int gid)throws ExceptionCommonBase{
		return dao.listPackageName(gid);
	}
	
}
